package com.boruishangge.home.acitivity;

import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.boruishangge.common.APlusARoute;
import com.boruishangge.home.R;
import com.boruishangge.home.adapter.HomePagerAdapter;
import com.boruishangge.home.bean.HomeTabBean;
import com.boruishangge.home.databinding.ActivityTableViewBinding;
import com.boruishangge.home.fragment.HomeListFragment;
import com.boruishangge.home.viewhelp.HomeFragmentViewHelp;
import com.boruishangge.home.viewhelp.TableActivityViewHelp;
import com.boruishangge.persagysdk.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

@Route(path = APlusARoute.aplus_table_activty)
public class TableActivity extends BaseActivity implements View.OnClickListener {
    private ActivityTableViewBinding binding;
    private HomePagerAdapter homePagerAdapter ;
    private List<HomeTabBean> titleList=new ArrayList<>();
    private List<Fragment> mFragmentsList=new ArrayList<>();
      @Autowired
      String name;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ARouter.getInstance().inject(this);
        binding= DataBindingUtil.setContentView(this, R.layout.activity_table_view);
        whiteStatusBar();
        initView();
        initData();
        initListener();
    }

    private  void  initView(){
        homePagerAdapter=new HomePagerAdapter(getSupportFragmentManager());
        titleList.addAll(TableActivityViewHelp.getTabData());
        TableActivityViewHelp.initMagicIndicator(binding.lvMagicIndicator,binding.vpContent,titleList,this);
        for (HomeTabBean name:titleList){
            HomeListFragment orderListFragment=new HomeListFragment();
            Bundle bundle = new Bundle();
            bundle.putString("name", name.getName());
            orderListFragment.setArguments(bundle);
            mFragmentsList.add(orderListFragment);
        }
        homePagerAdapter.addFragment(mFragmentsList);
        binding.vpContent.setAdapter(homePagerAdapter);

    }

    private  void  initData(){
        binding.tvTitle.setText(name);
    }
    private  void  initListener(){

        binding.ivBack.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v==binding.ivBack){
            finish();
        }
    }
}
